package com.wanshi.servlet;

import com.wanshi.entity.Product;
import com.wanshi.service.ProdService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/prodInfo")
public class prodInfo extends HttpServlet {

    private ProdService prodService = new ProdService();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //1 获取jsp传递的id
        String id = request.getParameter("id");

        //2 根据id到数据库查询
        Product prod = prodService.findProdById(id);

        //3 存入requestyu  请求转发
        request.setAttribute("prod",prod);
        request.getRequestDispatcher("/prodInfo.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}

